/*
 * Copyright (C) 2004, Velocityme Partnership
 * GroupBean.java
 *
 * Created on 25 July 2004, 07:14
 */

package com.velocityme.entity;

import javax.ejb.*;
import javax.naming.*;
import java.rmi.*;
import javax.rmi.*;
import com.velocityme.interfaces.*;
import com.velocityme.valueobjects.UserValue;
import com.velocityme.interfaces.ServiceUnavailableException;

/**
 *
 * @author  Robert
 * @ejb.bean
 *           type="CMP"
 *           cmp-version="2.x"
 *           name="Group"
 *           jndi-name="ejb/Group"
 *           view-type="local"
 * @ejb.transaction type="Required"
 *
 * @ejb.value-object match="*"
 *
 * @ejb.persistence table-name="group"
 *
 * @ejb.util generate="physical"
 *
 * @ejb.finder signature="java.util.Collection findAll()"
 *              query="SELECT OBJECT(o) FROM Group o WHERE o.nodeLocal.dBObjectLocal.isDeleted = FALSE"
 *
 * @jboss.persistence create-table="true"
 *                    remove-table="false"
 */
public abstract class GroupBean implements EntityBean {
    
    /**
    * Context set by container
    */
    private javax.ejb.EntityContext m_entityContext;

    public void setEntityContext(javax.ejb.EntityContext entityContext) {
        m_entityContext = entityContext;
    }

    public void unsetEntityContext() {
        m_entityContext = null;
    }
  
    /** @ejb.create-method */
    public com.velocityme.interfaces.GroupPK ejbCreate(com.velocityme.interfaces.NodeLocal p_nodeLocal,
                                                       com.velocityme.valueobjects.GroupValue p_value,
                                                       java.util.Collection p_usersLocal) throws CreateException {
        setGroupId(p_nodeLocal.getNodeId());
        // EJB 2.0 spec says return null for CMP ejbCreate methods.
        return null;
    }

    public void ejbPostCreate(com.velocityme.interfaces.NodeLocal p_nodeLocal,
                              com.velocityme.valueobjects.GroupValue p_value,
                              java.util.Collection p_usersLocal) throws CreateException {
        // CMR relations must be set in ejbPostCreate
        setGroupValue(p_value);
        setNodeLocal(p_nodeLocal);
        setUsersLocal(p_usersLocal);
    }

    /**
     *  This gets a local object from a remote object.
     *  @ejb.interface-method view-type="remote"
     */
    public com.velocityme.interfaces.GroupLocal getLocal() {
        return (GroupLocal)m_entityContext.getEJBLocalObject();
    }
    
    /** @ejb.interface-method view-type="local" */
    public abstract com.velocityme.valueobjects.GroupValue getGroupValue();
    /** @ejb.interface-method view-type="local" */
    public abstract void setGroupValue(com.velocityme.valueobjects.GroupValue p_value);

    //=======================================================================
    //
    //                   ATTRIBUTES
    //
    //=======================================================================
      
    /**
     * @ejb.persistence column-name="groupId"
     * @ejb.interface-method view-type="local"
     * @ejb.pk-field 
     */
    public abstract java.lang.Integer getGroupId();
    /** @ejb.interface-method view-type="local" */
    public abstract void setGroupId(java.lang.Integer groupId);

    //=======================================================================
    //
    //                   RELATIONSHIPS
    //
    //=======================================================================
    
    /**
     * @ejb.interface-method view-type="local"
     * @ejb.relation name="Group-Node"
     *               role-name="Group-has-a-Node"
     * @jboss.relation fk-column="nodeIdFk"
     *                 related-pk-field="nodeId"
     * @ejb.value-object match="*" 
     *                   aggregate="com.velocityme.valueobjects.NodeValue"
     *                   aggregate-name="NodeValue"
     */
    public abstract com.velocityme.interfaces.NodeLocal getNodeLocal();
    /** @ejb.interface-method view-type="local" */
    public abstract void setNodeLocal(com.velocityme.interfaces.NodeLocal nodeLocal);
    
    /**
     * @ejb.interface-method view-type="local"
     * @ejb.relation name="User-Group"
     *               role-name="Group-may-have-many-Users"
     * @jboss.relation fk-column="groupId"
     *                 related-pk-field="userId"
     * @jboss.relation-table table-name="usergroups"
     *                       create-table="true"
     *                       remove-table="false"
     */
    public abstract java.util.Collection getUsersLocal();
    /** @ejb.interface-method view-type="local" */
    public abstract void setUsersLocal(java.util.Collection usersLocal);
    
    /**
     * @ejb.interface-method view-type="local"
     * @ejb.relation name="GroupAccess-Group"
     *               role-name="Group-may-have-many-GroupAccesses"
     */
    public abstract java.util.Collection getGroupAccessesLocal();
    /** @ejb.interface-method view-type="local" */
    public abstract void setGroupAccessesLocal(java.util.Collection groupAccessesLocal);
    
    //=======================================================================
    //
    //                   MANAGEMENT METHODS
    //
    //=======================================================================
    
}
